using System;
using System.Collections.Generic;
using UnityEngine;

namespace EnemyClasses
{
//	public delegate void EnemyDieHandler (int ID);

	[RequireComponent (typeof(Rigidbody))]
	[RequireComponent (typeof(Mesh))]
	[RequireComponent (typeof(CapsuleCollider))]
	[RequireComponent (typeof(MeshRenderer))]
	public class Enemy : MonoBehaviour
	{
		//Static List
		private static Dictionary<int,Enemy> EnemyList = new Dictionary<int, Enemy>();
		private static int NextID = 0;

		//Class Variables
		private bool alive;
		private int health;
		private int Id;

		//Events
		//public static event EnemyDieHandler EnemyDieEvent;

		//Class Control Variables
		public static int NumberOfEnemies = 0;

		void Awake ()
		{
			alive = true;
			health = 100;
			NumberOfEnemies++;
			Id = NextID;
			NextID++;
			EnemyList.Add(Id,this);
		}

		void OnDestroy ()
		{
			NumberOfEnemies--;
			EnemyList.Remove(Id);
		}

		void Update ()
		{
			if (health <= 0) {
				Alive = false;
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="EnemyClasses.Enemy"/> is alive.
		/// </summary>
		/// <value><c>true</c> if alive; otherwise, <c>false</c>.</value>
		public bool Alive {
			get {
				return alive;
			}
			set {
				alive = value;
//				if (EnemyDieEvent != null) {
//					EnemyDieEvent (Id);
//				}
			}
		}

		/// <summary>
		/// Gets the <see cref="EnemyClasses.Enemy"/> at the specified index.
		/// </summary>
		/// <param name="index">Index.</param>
		public Enemy this[int index]{
			get{
				return EnemyList[index];
			}
		}

		/// <summary>
		/// Gets or sets the health.
		/// </summary>
		/// <value>The health.</value>
		public int Health {
			get {
				return health;
			}
			set {
				health = value;
			}
		}

		/// <summary>
		/// Gets or sets the ID.
		/// </summary>
		/// <value>The Id.</value>
		public int ID {
			get {
				return Id;
			}
			set {
				Id = value;
			}
		}
	}
}

